import tkinter as tk
from tkinter import filedialog
import subprocess
import sys


def analyze_scores():
    # 打开文件选择对话框
    file_path = filedialog.askopenfilename()

    if file_path:
        # 获取Python解释器路径
        python_path = sys.executable

        # 调用SmartScoreDescribe.py执行成绩分析
        cmd = [python_path, 'smartScoreDescribe.py', file_path]
        result = subprocess.run(cmd, capture_output=True, text=True)

        # 获取分析结果
        output = result.stdout

        # 在窗口上显示结果
        result_text.delete("1.0", tk.END)  # 清空文本框内容
        result_text.insert(tk.END, output)


# 创建Tkinter窗口
window = tk.Tk()
window.title("成绩分析")

# 创建文件选择标签
file_label = tk.Label(window, text="选择成绩文件：")
file_label.pack()

# 创建上传按钮
upload_button = tk.Button(window, text="上传成绩文件", command=analyze_scores)
upload_button.pack()

# 创建用于显示结果的文本框
result_label = tk.Label(window, text="处理结果：")
result_label.pack()

result_text = tk.Text(window, height=10, width=50)
result_text.pack()

# 启动窗口消息循环
window.mainloop()
